package com.example.logistics_oa.controller;

import com.example.comment_oa.pojos.JobMakeoffer;
import com.example.comment_oa.pojos.JobcorresSubsidy;
import com.example.comment_oa.pojos.XgZhiweibutie;
import com.example.comment_oa.pojos.XgZhiweijiben;
import com.example.comment_oa.pojos_vo.JibenSalaryChaXunVo;
import com.example.comment_oa.pojos_vo.XgZhiweijibenVo;
import com.example.comment_oa.response.AjaxResponse;
import com.example.logistics_oa.mapper.JobcorresSubsidyMapper;
import com.example.logistics_oa.service.JobMakeofferService;
import com.example.logistics_oa.service.JobcorresSubsidyService;
import com.example.logistics_oa.service.XgZhiweibutieService;
import com.example.logistics_oa.service.XgZhiweijibenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:  员工薪资构成  职位基本薪资表 Controller
 * @Author:李博文
 * @Date:2022/10/17 8:52
 */
@RestController
@RequestMapping("/logisticsOa")
@CrossOrigin
public class EmployeeSalaryGouChengController {

    @Autowired
    JobMakeofferService jobMakeofferService;
    @Autowired
    XgZhiweijibenService xgZhiweijibenService;
    @Autowired
    XgZhiweibutieService xgZhiweibutieService;


    @Autowired
    JobcorresSubsidyService jobcorresSubsidyService;

    @PostMapping("/SalaryGouCheng/jiben")
    public AjaxResponse selectJibenSalary(@RequestBody JibenSalaryChaXunVo jibenSalaryChaXunVo){

        List<JobMakeoffer> jobMakeoffers = jobMakeofferService.selectAll(jibenSalaryChaXunVo);
        return AjaxResponse.success(jobMakeoffers);
    }

    @PutMapping("/SalaryGouCheng/gangweijintie/{num}/{jintieId}")
    public AjaxResponse xiugaijintie(@PathVariable("num")Double jmoJobsalary, @PathVariable("jintieId")int jmoId, @RequestBody XgZhiweijiben xgZhiweijiben){
        int i = jobMakeofferService.updateGangWeiJinTie(jmoJobsalary, jmoId);
        System.out.println(xgZhiweijiben);
        xgZhiweijiben.setXgNeirong("岗位津贴");
        if(xgZhiweijiben.getXgBefore()<xgZhiweijiben.getXgAfter()){
            xgZhiweijiben.setXgProperty("上调");
        }else if (xgZhiweijiben.getXgBefore() > xgZhiweijiben.getXgAfter()){
            xgZhiweijiben.setXgProperty("下降");
        }
        xgZhiweijibenService.insertJilu(xgZhiweijiben);
        return AjaxResponse.success();
    }

    @PutMapping("/SalaryGouCheng/min/{minsalary}/{jintieId}")
    public AjaxResponse xiugaiMin(@PathVariable("minsalary")Double jmoMinsalary,@PathVariable("jintieId")int jmoId,@RequestBody XgZhiweijiben xgZhiweijiben){

        jobMakeofferService.updateMinSalary(jmoMinsalary, jmoId);
        xgZhiweijiben.setXgNeirong("最低基本薪资");
        if(xgZhiweijiben.getXgBefore()<xgZhiweijiben.getXgAfter()){
            xgZhiweijiben.setXgProperty("上调");
        }else if (xgZhiweijiben.getXgBefore() > xgZhiweijiben.getXgAfter()){
            xgZhiweijiben.setXgProperty("下降");
        }
        xgZhiweijibenService.insertJilu(xgZhiweijiben);
        return AjaxResponse.success();
    }

    @PutMapping("/SalaryGouCheng/max/{maxsalary}/{jintieId}")
    public AjaxResponse xiugaiMax(@PathVariable("maxsalary")Double maxsalary,@PathVariable("jintieId")int jmoId,@RequestBody XgZhiweijiben xgZhiweijiben){

        xgZhiweijiben.setXgNeirong("最高基本薪资");
        if(xgZhiweijiben.getXgBefore()<xgZhiweijiben.getXgAfter()){
            xgZhiweijiben.setXgProperty("上调");
        }else if (xgZhiweijiben.getXgBefore() > xgZhiweijiben.getXgAfter()){
            xgZhiweijiben.setXgProperty("下降");
        }
        xgZhiweijibenService.insertJilu(xgZhiweijiben);
        jobMakeofferService.updateMaxSalary(maxsalary, jmoId);
        return AjaxResponse.success();
    }

//很垃圾的代码   一次性同时修改，，然后同时新增两条修改记录
    @PutMapping("/SalaryGouCheng/maxandmin/{minsalary}/{maxsalary}/{jintieId}")
    public AjaxResponse xiugaiMaxAndMin(@PathVariable("maxsalary")Double maxsalary,@PathVariable("minsalary")Double minsalary,@PathVariable("jintieId")int jmoId,@RequestBody XgZhiweijibenVo XgZhiweijibenVo){
        XgZhiweijiben xgZhiweijiben = new XgZhiweijiben();
        xgZhiweijiben.setXgDepartmentname(XgZhiweijibenVo.getXgDepartmentname());
        xgZhiweijiben.setXgJob(XgZhiweijibenVo.getXgJob());
        xgZhiweijiben.setXgNeirong("职位最高薪资");
        xgZhiweijiben.setXgBefore(XgZhiweijibenVo.getXgBefore1());
        xgZhiweijiben.setXgAfter(XgZhiweijibenVo.getXgAfter1());
        xgZhiweijiben.setXgPerson(XgZhiweijibenVo.getXgPerson());
        if(XgZhiweijibenVo.getXgBefore1()<XgZhiweijibenVo.getXgAfter1()){
            xgZhiweijiben.setXgProperty("上调");
        }else if (xgZhiweijiben.getXgBefore() > xgZhiweijiben.getXgAfter()){
            xgZhiweijiben.setXgProperty("下降");
        }
        xgZhiweijiben.setXgPersongonghao(XgZhiweijibenVo.getXgPersongonghao());
        xgZhiweijibenService.insertJilu(xgZhiweijiben);


        xgZhiweijiben.setXgNeirong("职位最低薪资");
        xgZhiweijiben.setXgBefore(XgZhiweijibenVo.getXgBefore2());
        xgZhiweijiben.setXgAfter(XgZhiweijibenVo.getXgAfter2());
        if(XgZhiweijibenVo.getXgBefore2()<XgZhiweijibenVo.getXgAfter2()){
            xgZhiweijiben.setXgProperty("上调");
        }else if (xgZhiweijiben.getXgBefore() > xgZhiweijiben.getXgAfter()){
            xgZhiweijiben.setXgProperty("下降");
        }
        xgZhiweijibenService.insertJilu(xgZhiweijiben);

        jobMakeofferService.updateMaxAndMin(maxsalary, minsalary, jmoId);
        return AjaxResponse.success();
    }

    @PutMapping("/SalaryGouCheng/gaibutie/{jcsId}")
    public AjaxResponse xiugaibutiezhuangtai(@PathVariable("jcsId")int jcsId,@RequestBody XgZhiweibutie xgZhiweibutie){
        jobcorresSubsidyService.updateButieStatus(jcsId);
        xgZhiweibutie.setXgProperty("禁用补贴");
        xgZhiweibutieService.insertJilu(xgZhiweibutie);
        return AjaxResponse.success();
    }

    @PutMapping("/SalaryGouCheng/gaibutieQi/{jcsId}")
    public AjaxResponse xiugaibutiezhuangtai2(@PathVariable("jcsId")int jcsId,@RequestBody XgZhiweibutie xgZhiweibutie){
        jobcorresSubsidyService.updateButieStatusQi(jcsId);
        xgZhiweibutie.setXgProperty("启用补贴");
        xgZhiweibutieService.insertJilu(xgZhiweibutie);
        return AjaxResponse.success();
    }

    @PutMapping("/SalaryGouCheng/gaibutieMOney/{jcsMoney}/{jcsId}")
    public AjaxResponse xiugaibutiedeqian(@PathVariable("jcsId")int jcsId,@PathVariable("jcsMoney") Double jcsMoney,@RequestBody XgZhiweibutie xgZhiweibutie ){

        if(xgZhiweibutie.getXgBefore() < xgZhiweibutie.getXgAfter()){
            xgZhiweibutie.setXgProperty("上调");
        }else if(xgZhiweibutie.getXgBefore() > xgZhiweibutie.getXgAfter()){
            xgZhiweibutie.setXgProperty("下降");
        }
        xgZhiweibutieService.insertJilu(xgZhiweibutie);

        jobcorresSubsidyService.updateButieMoney(jcsMoney,jcsId);
        return AjaxResponse.success();
    }


    @GetMapping("/SalaryGouCheng/ZhiWeiXiaLa")
    public AjaxResponse chaxunxualakuang(){
        List<JobcorresSubsidy> jobcorresSubsidies = jobcorresSubsidyService.selectZhiWeiIdAndName();
        return AjaxResponse.success(jobcorresSubsidies);
    }

    @PostMapping("/SalaryGouCheng/xinzeng/{xgPerson}/{xgPersongonghao}")
    public AjaxResponse xinzengyitiao(@PathVariable("xgPerson")String xgPerson, @PathVariable("xgPersongonghao")String xgPersongonghao,@RequestBody JobcorresSubsidy jobcorresSubsidy){
        //从前台拿到对应的职位ID
        Integer jcsJobid = jobcorresSubsidy.getJcsJobid();
        //查出要的到的信息
        JobcorresSubsidy jobcorresSubsidy1 = jobcorresSubsidyService.selectOneByJcsjobid(jcsJobid);
        jobcorresSubsidy.setJcsJob(jobcorresSubsidy1.getJcsJob());
        jobcorresSubsidy.setJcsDepartmentid(jobcorresSubsidy1.getJcsDepartmentid());
        jobcorresSubsidy.setJcsDepartmentname(jobcorresSubsidy1.getJcsDepartmentname());
        jobcorresSubsidyService.insertJiLu(jobcorresSubsidy);
        XgZhiweibutie xgZhiweibutie = new XgZhiweibutie();
        xgZhiweibutie.setXgPerson(xgPerson);
        xgZhiweibutie.setXgPersongonghao(xgPersongonghao);
        xgZhiweibutie.setXgButiename(jobcorresSubsidy.getJcsSubname());
        xgZhiweibutie.setXgAfter(jobcorresSubsidy.getJcsMoney());
        xgZhiweibutie.setXgProperty("新增");
        xgZhiweibutie.setXgDepartmentname(jobcorresSubsidy1.getJcsDepartmentname());
        xgZhiweibutie.setXgJobname(jobcorresSubsidy1.getJcsJob());
        xgZhiweibutieService.insertJilu(xgZhiweibutie);
        return AjaxResponse.success();
    }

    @GetMapping("/SalaryGouCheng/BuMenXiaLa")
    public AjaxResponse chaxunxualakuang2(){
        List<JobcorresSubsidy> jobcorresSubsidies = jobcorresSubsidyService.selectBumenAndBumenName();
        return AjaxResponse.success(jobcorresSubsidies);
    }
//    查出来谁没有，然后给没有的新增一条数据
    @GetMapping("/SalaryGouCheng/GenjuTiaoJianChaXun/{jcsDepartmentid}/{jcsDepartmentname}/{jcsMoney}/{xgPerson}/{xgPersongonghao}")
    public AjaxResponse genjutiaojianchaxun(@PathVariable("jcsDepartmentid")int jcsDepartmentid,@PathVariable("jcsDepartmentname")String jcsDepartmentname,@PathVariable("jcsMoney")Double jcsMoney,@PathVariable("xgPerson")String xgPerson,@PathVariable("xgPersongonghao")String xgPersongonghao){
        List<JobcorresSubsidy> jobcorresSubsidies = jobcorresSubsidyService.selectGenJuTiaoJian(jcsDepartmentid, jcsDepartmentname, jcsMoney);
        System.err.println(jobcorresSubsidies);
        for (JobcorresSubsidy jobcorresSubsidy : jobcorresSubsidies) {
            jobcorresSubsidy.setJcsSubname(jcsDepartmentname);
            jobcorresSubsidy.setJcsMoney(jcsMoney);
            XgZhiweibutie xgZhiweibutie = new XgZhiweibutie();
            xgZhiweibutie.setXgPerson(xgPerson);
            xgZhiweibutie.setXgPersongonghao(xgPersongonghao);
            xgZhiweibutie.setXgButiename(jobcorresSubsidy.getJcsSubname());
            xgZhiweibutie.setXgAfter(jobcorresSubsidy.getJcsMoney());
            xgZhiweibutie.setXgProperty("新增");
            xgZhiweibutie.setXgDepartmentname(jobcorresSubsidy.getJcsDepartmentname());
            xgZhiweibutie.setXgJobname(jobcorresSubsidy.getJcsJob());
            xgZhiweibutieService.insertJilu(xgZhiweibutie);
            jobcorresSubsidyService.insertJiLu(jobcorresSubsidy);
        }
        return AjaxResponse.success();
    }


    @GetMapping("/SalaryGouCheng/BuTieXiangQing/{jcsJobid}/{jcsDepartmentid}")
    public AjaxResponse genjutiaoButieXiangQing(@PathVariable("jcsJobid")int jcsJobid,@PathVariable("jcsDepartmentid")int jcsDepartmentid){
        List<JobcorresSubsidy> jobcorresSubsidies = jobcorresSubsidyService.selectBuTieXiangQing(jcsJobid, jcsDepartmentid);
        return AjaxResponse.success(jobcorresSubsidies);
    }




}
